// 订单详情类 还有订单类

// 订单跟订单详情 是一对多的关系

class Order {
  public orderId: number;
  public date: Date;

  public custname: string;

  public phone: string;
  public orderDetails: OrderDetail[]; // 订单详情
  constructor(
    orderId: number,
    date: Date,
    custname: string,
    phone: string,
    orderDetails: OrderDetail[]
  ) {
    this.orderId = orderId;
    this.date = date;
    this.phone = phone;
    this.custname = custname;
    this.orderDetails = orderDetails;
  }
}

class OrderDetail {
  // public orderDetailId: number;
  // public productname: string;
  public price!: number; // 购买商品的价格 // ? 解决不用赋值undefined的问题( 但是现在尝试 不需要)
  // public count: number; // 购买数量

  // ! 1.如果你在构造器的参数加上public 这个参数就变成了一个属性
  // ! 2.等于默认构造函数会给这个属性赋值[隐式操作]
  constructor(
    public orderDetailId: number,
    public productname: string,
    public count: number
  ) {
    // this.orderDetailId = orderDetailId;
    // this.price = price;
    // this.productname = productname;
    // this.count = count;
  }

  public getTotal(): number {
    return this.price * this.count;
  }
}

const detail1 = new OrderDetail(1, "苹果", 1);

const order = new Order(1, new Date(), "张三", "111", [detail1]);

console.log("total", detail1.getTotal());

console.log(order);
